//package com.zx.flow.core.config;
//
//import com.zx.flow.api.dict.FlowDict.StorageType;
//import com.zx.flow.core.annotation.EnableLuckFlow;
//import com.zx.flow.spi.db.FlowStorageDBHandler;
//import com.zx.flow.spi.mock.FlowStorageMockHandler;
//import java.util.Set;
//import org.springframework.beans.factory.config.BeanDefinition;
//import org.springframework.beans.factory.support.BeanDefinitionRegistry;
//import org.springframework.beans.factory.support.BeanNameGenerator;
//import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
//import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
//import org.springframework.core.annotation.AnnotationAttributes;
//import org.springframework.core.type.AnnotationMetadata;
//import org.springframework.core.type.filter.AnnotationTypeFilter;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//
//public class LuckFlowRegistrar implements ImportBeanDefinitionRegistrar {
//
//    @Override
//    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry,
//            BeanNameGenerator importBeanNameGenerator) {
//
//        AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(
//                EnableLuckFlow.class.getName()));
//        StorageType storageType = attributes.getEnum("storageType");
//        ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
//        scanner.addIncludeFilter(new AnnotationTypeFilter(Component.class));
//
//        String packageName = "";
//        String storageBasePackage = attributes.getString("storageBasePackage");
//        if (!StringUtils.isEmpty(storageBasePackage)) {
//            packageName = storageBasePackage;
//        } else if (StorageType.db.equals(storageType)) {
//            packageName = FlowStorageDBHandler.class.getPackageName();
//            scanner.addIncludeFilter(new AnnotationTypeFilter(Component.class));
//        } else if (StorageType.mock.equals(storageType)) {
//            packageName = FlowStorageMockHandler.class.getPackageName();
//        }
//        Set<BeanDefinition> beanDefinitions = scanner.findCandidateComponents(packageName);
//        for (BeanDefinition beanDefinition : beanDefinitions) {
//            // 注册mysql相关的bean定义
//            registry.registerBeanDefinition(beanDefinition.getBeanClassName(), beanDefinition);
//        }
//    }
//}